package org.jeecg.modules.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: jeecg-boot
 * @Date:   2023-05-13
 * @Version: V1.0
 */
@Api(tags="测试")
@RestController
@RequestMapping("/sys/api/test")
@Slf4j
public class TestController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @ApiOperation(value="存储数据_leftPush", notes="存储数据")
    @GetMapping(value = "/leftPush")
    public Result<?> leftPush(String key,String value){
        Long res = redisTemplate.opsForList().leftPush(key,value);
        return Result.OK(res);
    }

    @ApiOperation(value="获取数据_rightPop", notes="获取数据")
    @GetMapping(value = "/rightPop")
    public Result<?> rightPop(String key){
        Object o = redisTemplate.opsForList().rightPop(key);
        return Result.OK(o);
    }

    @ApiOperation(value="存储数据_rightPush", notes="存储数据")
    @GetMapping(value = "/rightPush")
    public Result<?> rightPush(String key,String value){
        Long res = redisTemplate.opsForList().rightPush(key,value);
        return Result.OK(res);
    }

    @ApiOperation(value="获取数据_leftPop", notes="获取数据")
    @GetMapping(value = "/leftPop")
    public Result<?> leftPop(String key){
        Object o = redisTemplate.opsForList().leftPop(key);
        return Result.OK(o);
    }

    @ApiOperation(value="获取数据_size", notes="获取数据")
    @GetMapping(value = "/size")
    public Result<?> size(String key){
        return Result.OK(redisTemplate.opsForList().size(key));
    }

    @ApiOperation(value="获取数据_range", notes="获取数据")
    @GetMapping(value = "/range")
    public Result<?> range(String key,Integer begin,Integer end){
        return Result.OK(redisTemplate.opsForList().range(key,begin,end));
    }

    @ApiOperation(value="获取数据_increment", notes="获取数据")
    @GetMapping(value = "/increment")
    public Result<?> increment(String key){
        return Result.OK(redisTemplate.opsForValue().increment(key));
    }

    @ApiOperation(value="获取数据_getincrement", notes="获取数据")
    @GetMapping(value = "/getincrement")
    public Result<?> getincrement(String key){
        return Result.OK(redisTemplate.opsForValue().get(key));
    }
    @ApiOperation(value="获取数据_decrement", notes="获取数据")
    @GetMapping(value = "/decrement")
    public Result<?> decrement(String key){
        return Result.OK(redisTemplate.opsForValue().decrement(key));
    }
}
